package com.bodystm.temperature.server;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.mimosa.common.dao.HibernateDao;

@Repository
public class UrineBagDao extends HibernateDao<UrineBag, String>{
	public List<UrineBag> find24ByEquipNoAndMeasureTime(String equipNo){//, Date measureTime){
		try {
			Session session = super.getSession();
			String sql="select * from t_urinebag where equipNo='"+equipNo+"' GROUP BY DATE_FORMAT(measureTime,'%y-%m-%d %H')";
			SQLQuery sqlquery=session.createSQLQuery(sql);
			List<UrineBag> list=session.createSQLQuery(sql).addEntity(UrineBag.class).list();
			return list;
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 获取某个病人用过所有的贴片的尿袋数据，每个小时获取一个数
	 * @param strMacs
	 * @return
	 */
	public List<UrineBag> find24ByMacsAndMeasureTime(String strMacs) {
		try {
			Session session = super.getSession();
			String sql="select * from t_urinebag where equipNo in ("+strMacs+") GROUP BY DATE_FORMAT(measureTime,'%y-%m-%d %H')";
			SQLQuery sqlquery=session.createSQLQuery(sql);
			//sqlquery.setMaxResults(48);
			List<UrineBag> list=session.createSQLQuery(sql).addEntity(UrineBag.class).list();
			return list;
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 获取某个病人用过所有的贴片的温度数据，每个小时获取一个数
	 * @param strMacs
	 * @return
	 */
	public List<UrineBag> findAllByMacs(String strMacs) {
		try {
			Session session = super.getSession();
			String sql="select * from t_urinebag where equipNo in ("+strMacs+") order by measureTime Asc";
			SQLQuery sqlquery=session.createSQLQuery(sql);
			List<UrineBag> list=session.createSQLQuery(sql).addEntity(UrineBag.class).list();
			return list;
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
}
